home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
pipeln10.zip
/
VALVE.C
< prev
next >
Wrap
Text File
|
1990-06-01
|
16KB
|
553 lines
/***************************************************************************
* VALVE vers 1.10, DOS *
* Control program for TSRs PIPELINE and AQUEDUCT *
* 03/06/90 *
* by James W. Birdsall *
* *
* compiles under Turbo C 2.0 *
* *
* This program contains the large-scale control functions for the TSRs *
* PIPELINE and AQUEDUCT, which connect COM1 and COM2 in software. *
* VALVE sets up the COM ports, enables and disables the TSR, and *
* removes it. *
* *
***************************************************************************/
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include <bios.h>
#include <ctype.h>
#define INTERFACEINT 0xF1 /* interrupt # of TSR/VALVE interface */
#define INTCONTROLPORT 0x21 /* 8259A interrupt enable mask port */
#define INTENABLE 0x01 /* type of interrupt to enable on UARTs */
#define LINEEMASK 0x0B /* mask: enable UART interrupts, raise lines */
#define LINEDMASK 0xF7 /* mask: disable UART interrupts, leave lines */
/* TO CHANGE FROM COM1 OR COM2, CHANGE THE */
/* FOLLOWING INTERRUPT AND PORT VALUES */
#define DISABLEMASK 0x18 /* mask to enable COM port interrupts */
#define ENABLEMASK 0xE7 /* mask to disable COM port interrupts */
#define COM1INT 0x0C /* interrupt number for COM1 */
#define COM2INT 0x0B /* interrupt number for COM2 */
#define COM1IER 0x3F9 /* Interrupt Enable Register on COM1 */
#define COM1MCR 0x3FC /* Modem Control Register on COM1 */
#define COM2IER 0x2F9 /* Interrupt Enable Register on COM2 */
#define COM2MCR 0x2FC /* Modem Control Register on COM2 */
/* END OF INTERRUPT AND PORT VALUES */
#define ENA 0x1 /* internal flags */
#define DISA 0x0
#define CHAIN 0x1
#define NOCHAIN 0x0
#define USER 0x0
#define INTERNAL 0x1
#define CHAINOFF 0x0
#define CHAINON 0x2
#define AQUEDUCT 'A' /* TSR identifiers */
#define PIPELINE 'P'
#undef inportb
#undef outportb
char copyright[] = "Copyright (c) 1990 James W. Birdsall. All Rights Reserved";
char VERSION[] = "1.10";
/* structure of data within TSR */
typedef struct {
int errors;
void far *B;
void far *oldB;
void far *C;
void far *oldC;
unsigned int PSPseg;
void far *oldinterface;
char enabled;
char chain;
/* the following fields are found only in AQUEDUCT */
int one_in_head, one_in_tail, two_in_head, two_in_tail;
char busyflag;
} paramblock;
/* structure of a DOS Memory Control Block */
typedef struct {
unsigned char type;
unsigned int owner;
unsigned int size;
char junk[11];
} MCB;
void swapvect(paramblock far *, int);
paramblock far *instcheck(void);
void disable_pipe(paramblock far *, int);
void enable_pipe(paramblock far *, int);
int remove_pipe(paramblock far *);
void setup(paramblock far *, int, char *[]);
void usage(void);
char TSRtype; /* stores type of TSR found */
char *TSRname; /* pointer to name of TSR found */
/**************************************************************************
* MAIN *
* Handles argument parsing, etc. *
**************************************************************************/
main(int argc, char *argv[])
{
paramblock far *params;
int temp;
/* check arguments */
if (argc < 1) {
usage();
}
/* check for installation and get far pointer to parameter block */
params = instcheck();
/* act according to first argument */
switch (argv[1][0]) {
/* SETUP */
case 'S':
case 's':
setup(params, argc, argv);
printf("%s set up and enabled OK.\n", TSRname);
break;
/* ENABLE OR ERROR COUNT */
case 'E':
case 'e':
/* ENABLE */
if ((argv[1][1] == 'N') || (argv[1][1] == 'n')) {
temp = USER | ((toupper(argv[2][0]) == 'C') ? CHAINON : CHAINOFF);
enable_pipe(params, temp);
printf("%s enabled.\n", TSRname);
}
/* ERROR COUNT */
else if (toupper(argv[1][1]) == 'R') {
printf("Error count is %d.\n", params->errors);
params->errors = 0;
}
else {
usage();
}
break;
/* DISABLE */
case 'D':
case 'd':
disable_pipe(params, USER);
printf("%s disabled.\n", TSRname);
break;
/* REMOVE */
case 'R':
case 'r':
if (remove_pipe(params)) {
printf("Removal of %s failed\n", TSRname);
}
else {
printf("%s removed OK.\n", TSRname);
}
break;
/* BAD COMMAND */
default:
usage();
break;
}
exit(0);
} /* end of MAIN */
/**************************************************************************
* SETUP *
* Sets up the comm ports. *
**************************************************************************/
void setup(paramblock far *params, int argc, char *argv[])
{
int baud;
unsigned char biosparam = 0x0;
/* check arguments */
if (argc < 4) {
usage();
}
/* get baud */
if ((baud = atoi(argv[2])) == 0) {
usage();
}
switch (baud) {
case 110:
break;
case 150:
biosparam |= 0x20;
break;
case 300:
biosparam |= 0x40;
break;
case 600:
biosparam |= 0x60;
break;
case 1200:
biosparam |= 0x80;
break;
case 2400:
biosparam |= 0xA0;
break;
case 4800:
biosparam |= 0xC0;
break;
case 9600:
biosparam |= 0xE0;
break;
default:
usage();
break;
}
/* get data bits */
switch (argv[3][0]) {
case '7':
biosparam |= 0x02;
break;
case '8':
biosparam |= 0x03;
break;
default:
usage();
break;
}
/* get parity */
switch (argv[3][1]) {
case 'N':
case 'n':
break;
case 'O':
case 'o':
biosparam |= 0x08;
break;
case 'E':
case 'e':
biosparam |= 0x18;
break;
default:
usage();
break;
}
/* get stop bits */
switch (argv[3][2]) {
case '1':
break;
case '2':
biosparam |= 0x04;
break;
default:
usage();
break;
}
/* all arguments verified, so start setup by turning pipeline off */
disable_pipe(params, INTERNAL);
/* set up ports 1 and 2 */
bioscom(0, biosparam, 0);
bioscom(0, biosparam, 1);
/* turn pipeline back on */
enable_pipe(params,
(INTERNAL | ((toupper(argv[4][0]) == 'C') ? CHAINON : CHAINOFF)));
return;
} /* end of SETUP */
/**************************************************************************
* DISABLE_PIPE *
* Disables the TSR. *
***